import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

// creates a new reservation in the database

public class SqlTest5
{
	
	  public static void main(String args[]) throws SQLException {
	
		  Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bedandbreakfast",
					  "root", "");	
		  Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, 
		                                       ResultSet.CONCUR_UPDATABLE);
		  
		  ResultSet uprs = stmt.executeQuery("SELECT P_id, guestName, roomNumber, totalNumberOfGuests, checkIn, checkOut, address, city, state, zip, phoneNumber, email FROM reservation");
				  
	      uprs.moveToInsertRow();

	      uprs.updateString("guestName", "Adam Confino");
	      uprs.updateInt("roomNumber", 105);
	      uprs.updateInt("totalNumberOfGuests", 2);
	      uprs.updateString("checkIn", "07-28-2010");
	      uprs.updateString("checkOut", "07-29-2010");
	      uprs.updateString("address", "50 Magnolia Drive");
	      uprs.updateString("city", "Douglassville");
	      uprs.updateString("state", "PA");
	      uprs.updateInt("zip", 19518);
	      uprs.updateString("phoneNumber", "610-327-3973");
	      uprs.updateString("email", "aconfino@gmail.com");

	      uprs.insertRow();

	      uprs.beforeFirst();

	      System.out.println("Reservation that was added:");
	      while (uprs.next()) {
	    	  String guestName = uprs.getString("guestName");
		      int roomNumber = uprs.getInt("roomNumber");
		      int totalNumberOfGuests = uprs.getInt("totalNumberOfGuests");
		      String checkIn = uprs.getString("checkIn");
		      String checkOut = uprs.getString("checkOut");
		      String address = uprs.getString("address");
		      String city = uprs.getString("city");
		      String state = uprs.getString("state");
		      int zip = uprs.getInt("zip");
		      String phone = uprs.getString("phoneNumber");
		     String email =  uprs.getString("email");
	       
		     System.out.println("Guest: " + guestName +"   Room Number: "+ roomNumber +"   Number of Guests: "+ totalNumberOfGuests +"   Check In: "+ checkIn +"   Check Out: "+ checkOut +"   Address: "+ address +"   City: "+ city +"   State: " +state +"   Zip: " +zip +"   Phone: "+ phone +  "   Email: "+ email);

	      }
		      
		}

	  

}
